<template>
  <div class="subject">
    <span>{{ item[0] }}</span>
    <span>+</span>
    <span>{{ item[1] }}</span>
    <span>=</span>
    <input type="number" v-model="answer" />
    <button @click="verify">提交</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      rightAnswer: 0,
      answer: "",
    };
  },
  props: ["item","index"],
  methods: {
    verify() {
      this.rightAnswer = this.item[2];

      if (!this.answer.trim()) {
        return;
      }

    //   console.log('this.rightAnswer',this.rightAnswer);
    //   console.log('this.answer',this.answer);

      return this.rightAnswer === Number(this.answer)
        ? this.$emit("res", `${this.index}-回答正确`)
        : this.$emit("res", `${this.index}-回答错误`);
    },
  },
};
</script>

<style scoped>
.subject {
  margin: 5px;
  padding: 5px;
  font-size: 20px;
}
.subject span {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.subject input {
  width: 50px;
  height: 20px;
}
</style>
